package com.alibaba.nacos.example.spring.cloud;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
public class TestController {
	
	private  final Logger log = LoggerFactory.getLogger(TestController.class);

	@LoadBalanced
	@Bean
	public RestTemplate restTemplate() {
		return new RestTemplate();
	}

	@Autowired
	private RestTemplate restTemplate;
	
	@Autowired
	private TestFeignDemo testFeign;

	@RequestMapping(value = "/echo/{str}", method = RequestMethod.GET)
	public String echo(@PathVariable String str) {
		
		String restTemplateResult = restTemplate.getForObject("http://service-provider/hello/echo/" + str, String.class);
		log.info("restTemplateResult调用获取的结果:"+restTemplateResult);
		
		String feignResult = testFeign.echo(str);
		log.info("feign调用获取的结果:"+feignResult);
		
		return "restTemplateResult="+restTemplateResult+",feignResult="+feignResult;
	}
}